﻿using CommonTools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FreeSql.DataAnnotations;
using System.Drawing;

namespace shop.Model
{
    /// <summary> 退换登记 </summary>
    public class RefundRegist:IDoc
    {
        [Column(IsPrimary = true, IsIdentity = true)]
        public int DocId { set; get; }


        [VarChar(20)]
        public string Number { get; set; }

        public DateTime? OccurDate { get; set; }

        [Column(StringLength = 50)]
        public string PreparedBy { get; set; }

        public DateTime? PreparedDate { get; set; }

        /// <summary> 处理人 </summary>
        [Column(StringLength =50)]
        public string Processor {  get; set; }  


        /// <summary> 快递单号 </summary>
        [Column(StringLength =500)]
        public string LogiNo { set; get; }

        /// <summary> 原始单号 </summary>
        [Column(StringLength = 500)]
        public string src_tids { set; get; }

        /// <summary> 单号 </summary>
        [Column(StringLength = 150)]
        public string trade_no { set; get; }

        /// <summary> 店铺 </summary>
        [Column(StringLength = 100)]
        public string Shop { set; get; }


        /// <summary> 产品id </summary>
        [Column(StringLength = 500)]
        public string platform_goods_id { set; get; }



        /// <summary> 商家编码 </summary>
        [Column(StringLength = 500)]
        public string spec_no { set; get; }


        /// <summary> 仓库 </summary>
        [Column(StringLength = 100)]
        public string Stock { set; get; }


        /// <summary> 旺旺号 </summary>
        [Column(StringLength = 50)]
        public string Wangwang { set; get; }

        /// <summary> 退货数量 </summary>
        [Column(Precision = 18, Scale = 4)]
        public decimal RefundQty { set; get; }

        /// <summary> 打款金额 </summary>
        [Column(Precision =18, Scale =4)]
        public decimal PayAmount { set; get; }

        /// <summary> 赔偿原因 </summary>
        [Column(StringLength =300)]
        public string Reason { set; get; }


        /// <summary> 赔偿原因 </summary>
        [Column(StringLength = 300)]
        public string Reason2 { set; get; }

        /// <summary> 赔偿原因 </summary>
        [Column(StringLength = 300)]
        public string Reason3 { set; get; }


        /// <summary> 赔偿原因 原始 </summary>
        [Column(StringLength = 200)]
        public string RefundReason { set; get; }


        /// <summary> 赔偿来源 </summary>
        [Column(StringLength =200)]
        public string RefundFrom { set; get; }


        [Column(StringLength = 500)]
        public string Remarks { set; get; }


        /// <summary> 是否已经发送消息 </summary>
        public bool IsSendMessage { set; get; }

        public byte? IsChecked { get; set; }

        [Column(StringLength = 30)]
        public string Checker { get; set; }

        public bool? Isdel { get; set; }

        public DateTime? IsdelDate { get; set; }

        public DateTime? LastModifyTime { get; set; }


        /// <summary> 图片 </summary>
        //[Column(StringLength = 4000)]
        [Column(IsIgnore = true)]
        public List<RefundRegistImage> ImageUrls { set; get; } = new List<RefundRegistImage>();




        [Column(IsIgnore = true)]
        public string SubTitle => string.IsNullOrEmpty(this.Number) ? "new" : this.Number + " " + this.Shop;

        [Column(IsIgnore = true)]
        public string DocFlag { get; set; } = DocFlagEnum.RefundRegist;

        [Column(IsIgnore = true)]
        public DateTime? ReadTime { get; set; }

        [Column(IsIgnore = true)]
        public string RedText => this.IsChecked > 0 ? "已审核" : string.Empty;


        #region 事件: 保存 删除, 

        public event Action<IDoc> DocDeleted;
        public void OnDocDeleted() => this.DocDeleted?.Invoke(this);

        public event Action<IDoc> DocSaved;
        public void OnDocSaved() => this.DocSaved?.Invoke(this);

        #endregion

    }


    public class RefundRegistImage
    {
        [Column(IsPrimary =true, IsIdentity =true)]
        public int id { get; set; }

        public int DocId { get; set; }


        public int ItemId { get; set; }


        [Column(StringLength =100)]
        public string FileName { get; set; }

        [Column(StringLength =500)]
        public string ImgUlr { get; set; }

        //[Column(StringLength =500)]
        [Column(IsIgnore =true)]
        public string ImgPath { get; set; }

        [Column(IsIgnore = true)]
        public Image Img { get; set; }


        public bool Isdel { get; set; }
    }

}
